import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { CType } from "./entities/common.entity";
import { FindCondition, Repository } from "typeorm";
import { ReqCodeKindDto } from "./dto/req-common.dto";

@Injectable()
export class CommonService {
  constructor(@InjectRepository(CType) private readonly cTypeRepository: Repository<CType>) {}

  /**
   * @description: 根据code_kind查询返回类型
   * @return {*}
   */
  async getCodeKinds(reqCodeKindDto: ReqCodeKindDto): Promise<CType[]> {
    const where: FindCondition<CType> = {};
    if (reqCodeKindDto.code_kind) {
      where.code_kind = reqCodeKindDto.code_kind;
    }
    return await this.cTypeRepository.createQueryBuilder("c_type").where(where).getMany();
  }
}
